//package com.pengzy.core.cloud_security;
//
//import com.pengzy.comment.core.enums.PrErrorEnum;
//import com.pengzy.comment.core.enums.SecurityEnum;
//import com.pengzy.comment.core.jwt.JwtUtil;
//import com.pengzy.comment.web.exception.CustomException;
//import com.pengzy.comment.web.redis.RedisCache;
//import io.jsonwebtoken.Claims;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.web.server.WebFilterExchange;
//import org.springframework.security.web.server.authentication.logout.ServerLogoutHandler;
//import org.springframework.stereotype.Component;
//import reactor.core.publisher.Mono;
//
//import javax.annotation.Resource;
//import java.util.Map;
//
///**
// * @author xiaozhi 2023/7/17
// */
//
//@Component
//@Slf4j
//public class LogoutHandler implements ServerLogoutHandler {
//
//
//    @Resource
//    private RedisCache redisCache;
//
//    @Override
//    public Mono<Void> logout(WebFilterExchange webFilterExchange, Authentication authentication) {
//        //HttpCookie cookie=webFilterExchange.getExchange().getRequest().getCookies().getFirst("token");
//        String token=webFilterExchange.getExchange().getRequest().getHeaders().getFirst("token");
//        try {
//            String user;
//            try {
//                Claims claims = JwtUtil.parseJWT(token);
//                user = claims.getSubject();
//            } catch (Exception e) {
//                throw new CustomException(PrErrorEnum.ERROR_1003.getInfo(),PrErrorEnum.ERROR_1003.getCode());
//            }
//            String redisKey = SecurityEnum.LOGIN_KEY.getValue() + user;
//            redisCache.deleteObject(redisKey);
//        }catch (Exception e) {
//            return Mono.error(e);
//        }
//        return Mono.empty();
//    }
//
//}
